1 /* JJT: 0.2.2 */
2
3 package mobisnap.mobile_trx;
4
5 import java.util.*;
6
7 /***
8 * Implements short-circuit AND
9 */
10 public class ASTSQLAndExpression extends mobisnap.mobile_trx.SimpleNode {
11 public Vector ands;
12
13 public ASTSQLAndExpression(int id) {
14 super(id);
15 ands = new Vector();
16 }
17
18 public ASTSQLAndExpression( MobisnapSQL p, int i) {
19 super( p, i);
20 id = i;
21 ands = new Vector();
22 }
23
24 /*** Accept the visitor. **/
25 public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) {
26 return visitor.visit(this, data);
27 }
28
29 /***
30 * Returns the value of the expression
31 *
32 * @param msql_type Specifies which type of processing should be performed
33 * MobisnapConstants.MSQL_SERVER = 1
34 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
35 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
36 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
37 * @param cond True if reservations associated iwth transaction should be
38 * propagated to the current transaction
39 */
40 public Object value( int msql_type, boolean cond) throws Exception {
41 int n = ands.size();
42 if( n == 0)
43 throw new Exception( "Internal error in and expression");
44 Object val = ((SimpleNode)ands.elementAt(0)).value( msql_type, cond);
45 for( int i = 1; i < n; i++) {
46 Object aux = ((SimpleNode)ands.elementAt( i)).value( msql_type, cond);
47 val = MSQLTypeUtil.and( val, aux);
48 }
49 return val;
50 }
51
52 /***
53 * Returns a simplified node, if possible (usefull in expressions)
54 *
55 * @param msql_type Specifies which type of processing should be performed
56 * MobisnapConstants.MSQL_SERVER = 1
57 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
58 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
59 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
60 * MobisnapConstants.MSQL_STATIC = 10
61 * @param cond True if reservations associated iwth transaction should be
62 * propagated to the current transaction
63 */
64 public SimpleNode simplify( int msql_type, boolean cond) {
65 for( int i = 0; i < ands.size(); i++)
66 ands.setElementAt( ((SimpleNode)ands.elementAt(i)).simplify( msql_type, cond), i);
67 if( ands.size() == 1)
68 return (SimpleNode)ands.elementAt( 0);
69 try {
70 return new SimpleNodeValue( value( msql_type, cond));
71 } catch( Exception e) {
72 return this;
73 }
74 }
75
76
77 }
This page was automatically generated by Maven